 //
//  SLFriendListTableViewCell.m
//  StarLight
//
//  Created by Duke.wu on 16/6/1.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLFriendListTableViewCell.h"
#import "SLShipOwnerVipLevelView.h"


@interface SLFriendListTableViewCell ()
@property (strong, nonatomic)  UILabel *zeroCountLB;

@property (strong, nonatomic)  UILabel *halfCountLB;

@property (strong, nonatomic)  UILabel *fullCount;

@property (nonatomic, strong)  UILabel *reserveCountLB;

@property (nonatomic, strong) SLFriendModel *friendModel;

@property (nonatomic, strong) UILabel *vipLabel;

@property (nonatomic, strong) SLShipOwnerVipLevelView *levelView;

/**搜索列表 用*/
@property (nonatomic, strong) UILabel *phoneLB;

@end


@implementation SLFriendListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
  self.selectionStyle = UITableViewCellSelectionStyleNone;

  self.nearDateLB.textColor = [UIColor whiteColor];
  self.nearDateLB.backgroundColor = SLYellowColor;

  [self.contentView addSubview:self.zeroCountLB];
  [self.contentView addSubview:self.halfCountLB];
  [self.contentView addSubview:self.fullCount];
  [self.contentView addSubview:self.reserveCountLB];
  [self.contentView addSubview:self.vipLabel];
  [self.contentView addSubview:self.levelView];
  [self.contentView addSubview:self.phoneLB];
  
  [self.zeroCountLB mas_makeConstraints:^(MASConstraintMaker *make) {
    make.bottom.equalTo(self.friendIcon);
    make.left.equalTo(self.friendIcon.mas_right).offset(8);
  }];
  
  [self.halfCountLB mas_makeConstraints:^(MASConstraintMaker *make) {
    make.bottom.equalTo(self.friendIcon);
    make.left.equalTo(self.zeroCountLB.mas_right).offset(4);
  }];
  
  [self.fullCount mas_makeConstraints:^(MASConstraintMaker *make) {
    make.bottom.equalTo(self.friendIcon);
    make.left.equalTo(self.halfCountLB.mas_right).offset(4);
  }];
  
  [self.reserveCountLB mas_makeConstraints:^(MASConstraintMaker *make) {
    make.bottom.equalTo(self.friendIcon);
    make.left.equalTo(self.fullCount.mas_right).offset(4);
  }];
  
  [self.vipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.equalTo(self.friendTypeLb.mas_right).offset(5);
    make.centerY.equalTo(self.friendTypeLb);
  }];
  
  [self.levelView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerY.equalTo(self.vipLabel);
    make.left.equalTo(self.vipLabel.mas_right).offset(5);
    make.size.mas_equalTo(CGSizeMake(20, 20));
  }];
  
  [self.phoneLB mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerY.equalTo(self.friendIcon);
    make.left.equalTo(self.friendTypeLb);
  }];
  
  
  UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction)];
  longPress.minimumPressDuration = 1.0;
  [self.contentView addGestureRecognizer:longPress];
}

- (void)longPressAction{
  if (_delegate &&[_delegate respondsToSelector:@selector(didLongPressCellWithModel:)]) {
    [_delegate didLongPressCellWithModel:self.friendModel];
  }
}

- (void)configFriendListCellWithModel:(SLFriendModel *)model{
  self.friendModel = model;
  [self hiddenWithType:model.type];
  
  NSString *zero = model.kNum == 0 ? @"" : [NSString stringWithFormat:@" 空船:%ld ",(long)model.kNum];
  NSString *half = model.bNum == 0 ? @"" : [NSString stringWithFormat:@" 半船:%ld ",(long)model.bNum];
  NSString *full = model.mNum == 0 ? @"" : [NSString stringWithFormat:@" 满船:%ld ",(long)model.mNum];
  NSString *reserve = model.yNum ==0 ? @"" : [NSString stringWithFormat:@" 预定:%ld",(long)model.yNum];
  
  self.zeroCountLB.text = zero;
  self.halfCountLB.text = half;
  self.fullCount.text = full;
  self.reserveCountLB.text = reserve;
  if (model.goodsNum != 0) {
    self.nearDateLB.hidden = NO;
      self.nearDateLB.text = [NSString stringWithFormat:@" 最近发货:%ld单",(long)model.goodsNum];
  }else{
    self.nearDateLB.hidden = YES;
  }
  
  [self.friendIcon sd_setImageWithURL:[NSURL URLWithString:model.headPhoto] placeholderImage:[UIImage imageNamed:@"head"]];
  self.nameLb.text = model.name;
  
  if (model.role < 1) {
    self.vipLabel.hidden = YES;
    self.levelView.hidden = YES;
  }else{
    self.vipLabel.hidden = NO;
    self.levelView.hidden = NO;
    [self.levelView configWithLevel:[NSString stringWithFormat:@"%ld",(long)model.role]];
  }
  
  if (model.phone) {
    self.phoneLB.text = model.phone;
  }
  
}


- (void)hiddenWithType:(NSInteger)type{
  if (type == 0 ) {
    self.nearDateLB.hidden = YES;
    self.zeroCountLB.hidden = NO;
    self.halfCountLB.hidden = NO;
    self.fullCount.hidden = NO;
    self.reserveCountLB.hidden = NO;
    self.friendTypeLb.text = @"船主";
  }else{
    self.friendTypeLb.text = @"货主";
    self.zeroCountLB.hidden = YES;
    self.halfCountLB.hidden = YES;
    self.fullCount.hidden = YES;
    self.reserveCountLB.hidden = YES;
    self.nearDateLB.hidden = NO;
  }

}


-(UILabel *)zeroCountLB{
  if (!_zeroCountLB) {
    _zeroCountLB = [UILabel labelWithFontSize:16 textColor:[UIColor whiteColor]];
    _zeroCountLB.backgroundColor = SLYellowColor;
  }
  return _zeroCountLB;
}


- (UILabel *)halfCountLB{
  if (!_halfCountLB) {
    _halfCountLB = [UILabel labelWithFontSize:16 textColor:[UIColor whiteColor]];
    _halfCountLB.backgroundColor = SLYellowColor;
  }
  return _halfCountLB;
}

- (UILabel *)fullCount{
  if (!_fullCount) {
    _fullCount = [UILabel labelWithFontSize:16 textColor:[UIColor whiteColor]];
    _fullCount.backgroundColor = SLYellowColor;
  }
  return _fullCount;
}

- (UILabel *)reserveCountLB{
  if (!_reserveCountLB) {
    _reserveCountLB = [UILabel labelWithFontSize:16 textColor:[UIColor whiteColor]];
    _reserveCountLB.backgroundColor = SLYellowColor;
  }
  return _reserveCountLB;
}

-(UILabel *)vipLabel{
  if (!_vipLabel) {
    _vipLabel = [UILabel labelwithBoldFontSize:15 textColor:[UIColor redColor] text:@"VIP"];
  }
  return _vipLabel;
}

- (SLShipOwnerVipLevelView *)levelView{
  if (!_levelView) {
    _levelView = [SLShipOwnerVipLevelView new];
  }
  return _levelView;
}

- (UILabel *)phoneLB{
  if (!_phoneLB) {
    _phoneLB = [UILabel labelWithFontSize:14 textColor:SLInkColor];
    _phoneLB.textAlignment = NSTextAlignmentRight;
  }
  return _phoneLB;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
